<template>
  <div class="app-container">
    <!-- <el-button type="text" @click="dialogVisible = true">添加</el-button> -->
    <!-- <el-card shadow="never"> -->
      <!-- <div slot="header" style="text-align: center;">用户列表</div> -->
      <!-- 店铺店铺列表-->
      <div>
        <el-form>
          <el-row class="rowFormItem">
            <el-col :span="3">
              <el-input v-model="keyword" placeholder="请输入昵称搜索" />
            </el-col>
            <!-- 提交按钮 -->
            <el-col :span="5" class="clear">
              <el-form-item style="text-align: center;width: 150px;margin-left: 10px;">
                <el-button type="primary" size="large" @click="handleSubmit()">检索</el-button>
                <el-button type="warning" size="large" style="margin-left: 8px" @click="handleReset()">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="tableClass">
        <el-table :data="formdata" v-loading="loading" :header-cell-style="{background:'#eef1f6',color:'#606266'}"
          border style="width: 100%;">
          <el-table-column align="center" prop="id" label="序号" />
          <el-table-column align="center" prop="photo_url" label="用户头像">
            <template slot-scope="scope">
              <el-button type="text" size="medium">
                <img style="width: 50%;" :src="scope.row.user_info.photo_url" />
              </el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="user_info.nickname" label="昵称" />
          <el-table-column align="center" prop="user_info.sex" label="性别" />
          <el-table-column align="center" prop="user_info.sex" label="地区">
           <template slot-scope="scope">
               <div>{{scope.row.user_info.province}}/{{scope.row.user_info.city}}</div>
             </template>
           </el-table-column>
          <el-table-column align="center" prop="reg_time" label="注册时间" />
          <!-- <el-table-column label="操作" align="center" width="230px">
            <template slot-scope="scope">
              <el-button class="btnAppeal" size="small" type="warning" @click="updateMsg(scope.row)">修改</el-button>
              <el-button class="btnAppeal" size="small" type="danger" @click="delMsg(scope.row.id)">删除</el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <br>
        <!-- 分页 -->
        <div style="text-align: center;">
          <el-pagination background layout="prev, pager, next" @current-change="pageChange" :page-size="pageSize"
            :total="totalusers" />
        </div>
      </div>
    <!-- </el-card> -->
  </div>
</template>

<script>
  export default {
    data() {
      return {
        loading: false,
        keyword: "",
        formdata: [],
        totalusers: 0, //总行数
        pageSize: 5, //每页几行
        startpage: 1, //起始页
      }
    },
    mounted() {
      this.getUserList()
    },
    methods: {
      //搜索
      handleSubmit() {
        this.getUserList()
      },
      handleReset() {
        this.keyword = ""
      },
      //获取分页列表
      getUserList() {
        let params = {
          "page": this.startpage,
          "limit": this.pageSize,
          "keyword": this.keyword
        }
        //调用后台提供的接口方法
        this.$api.getUserList(params).then(res => {
          if (res.data.level == "success") {
            this.formdata = res.data.data
            this.totalusers = res.data.page_info.total
            this.loading = false
          } else {
            this.$message.error(res.data.message)
          }


        })
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.startpage = page
        this.loading = true
        //调用获取列表的方法
        this.getUserList()
      },
    }
  }
</script>
<style scoped="scoped">
  /deep/.el-card__header {
    background-color: #409EFF;
    color: whitesmoke;
  }

  /deep/.el-dialog {
    margin-top: 10vh !important;
    width: 33%;
  }

  .msgDiv {
    width: 80%;
    margin: auto;
    text-align: center;
  }

  .el-input {
    display: flex;
    flex-grow: <2>;
  }
</style>
